package controller.wechat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import service.Impl.WsToken;

/**
 * Created by thinkjoy on 2017/8/30.
 * 每次服务开始:Spring全部初始化完毕后会调用此监听来获取token
 */

public class WechatAcceptToken implements ApplicationListener<ContextRefreshedEvent>{

    @Autowired
    private WsToken wsToken;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
//        只在root application context容器初始化完成后调用
        if(contextRefreshedEvent.getApplicationContext().getParent() == null){
            wsToken.getToken();
        }
    }
}
